import request from '@/utils/request'

const BASE_URL = '/api/yyplatform/admin/layout/login'

class LoginAPI {
  /** 登录 接口*/
  static loginCheck(data: LoginData) {
    const formData = new FormData()
    formData.append('userName', data.username)
    formData.append('password', data.password)
    formData.append('captcha', data.captchaCode)
    formData.append('captchaUuid', data.captchaKey)
    return request<any, LoginResult>({
      url: `${BASE_URL}/loginCheck`,
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }

  static getCaptcha() {
    return request<any, CaptchaResult>({
      url: `${BASE_URL}/captcha`,
      method: 'get'
    })
  }
}

export default LoginAPI

export interface CaptchaResult {
  uuid: string
  image: string
}

export interface LoginResult {
  jwtToken: string
}

/** 登录请求参数 */
export interface LoginData {
  username: string
  /** 密码 */
  password: string
  /** 验证码缓存key */
  captchaKey: string
  /** 验证码 */
  captchaCode: string
}
